import { getCidApi, delListApi, updateListApi, addListApi } from "@/api/classify"

const state = {
    classifyList: []
}

const mutations = {
    SET_CIDS(state, classifyList) {
        state.classifyList = classifyList
    }
}

const actions = {
    async getCid({ commit }) {
        let { data } = await getCidApi()
        let r = [{}].concat(data)
        commit('SET_CIDS', r)
    },
    async addList({ dispatch }, data) {
        await addListApi(data)
        dispatch('getCid')
    },
    async delList({ dispatch }, id) {
        await delListApi(id)
        dispatch('getCid')
    },
    async updateList({ dispatch, state }, data) {
        await updateListApi(data)
        dispatch('getCid')
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}